import type { RouteRecordRaw } from 'vue-router';
import { Router } from 'vue-router';
import { useUserStore } from "@/store/modules/user"

const whitePathList = ['/login'];

export function createRouterGuards(router: Router) {
    router.beforeEach(async (to, from, next) => {
        if (whitePathList.includes(to.path)) {
            next();
            return;
        }

        const userStore = useUserStore()
        const { token } = storeToRefs(userStore)
        
        // 没有登录的逻辑 - 校验token
        // if(!token.value) {
        //     next('/login');
        //     return;
        // }
        
        next();
    })

    router.afterEach((to) => {

    });

    router.onError((error) => {
        console.log(error, '路由错误');
    });
}
